<template>
  <div class="payment-page">
    <!-- 顶部导航栏 -->


    <!-- 主要内容区域 -->
    <div class="main-content">
      <div class="container">
        <div class="payment-wrapper">
          <!-- 支付方式选择 -->
          <div class="payment-methods">
            <h3 class="section-title">选择支付方式</h3>
            <div class="method-list">
              <div
                v-for="method in paymentMethods"
                :key="method.id"
                class="method-item"
                :class="{ active: selectedMethod === method.id }"
                @click="selectMethod(method.id)"
              >
                <div class="method-info">
                  <img :src="method.icon" :alt="method.name" class="method-icon" />
                  <span class="method-name">{{ method.name }}</span>
                </div>
                <el-radio :value="method.id" v-model="selectedMethod" />
              </div>
            </div>
          </div>

          <!-- 订单信息 -->
          <div class="order-summary">
            <h3 class="section-title">订单详情</h3>
            <div class="order-info">
              <div class="order-item">
                <span class="item-label">订单号:</span>
                <span class="item-value">{{ orderInfo.orderNumber }}</span>
              </div>
              <div class="order-item">
                <span class="item-label">商品总价:</span>
                <span class="item-value">¥{{ orderInfo.totalPrice }}</span>
              </div>
              <div class="order-item">
                <span class="item-label">运费:</span>
                <span class="item-value">¥{{ orderInfo.shippingFee }}</span>
              </div>
              <div class="order-item">
                <span class="item-label">优惠金额:</span>
                <span class="item-value discount">-¥{{ orderInfo.discount }}</span>
              </div>
              <div class="order-item total">
                <span class="item-label">应付金额:</span>
                <span class="item-value final-amount">¥{{ finalAmount }}</span>
              </div>
            </div>
          </div>

          <!-- 安全提示 -->
          <div class="security-tips">
            <h3 class="section-title">安全提示</h3>
            <ul class="tips-list">
              <li>请您在30分钟内完成支付，否则订单将自动取消</li>
              <li>为了您的资金安全，请不要在网吧等公共场所进行支付操作</li>
              <li>支付完成前，请不要关闭此窗口</li>
              <li>遇到问题可以联系客服：400-000-0000</li>
            </ul>
          </div>

          <!-- 支付按钮 -->
          <div class="payment-actions">
            <div class="amount-display">
              <span class="amount-label">应付金额:</span>
              <span class="amount-value">¥{{ finalAmount }}</span>
            </div>
            <div class="action-buttons">
              <el-button size="large" @click="cancelPayment">取消支付</el-button>
              <el-button
                type="warning"
                size="large"
                @click="confirmPayment"
                :disabled="!selectedMethod"
                class="pay-btn"
              >
                确认支付
              </el-button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 支付成功对话框 -->
    <el-dialog
      v-model="showSuccessDialog"
      title="支付成功"
      width="400px"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <div class="success-content">
        <el-icon class="success-icon" color="#67c23a"><CircleCheck /></el-icon>
        <h3>支付成功！</h3>
        <p>您的订单已经支付成功，我们将尽快为您发货。</p>
        <div class="order-number">
          <span>订单号: {{ orderInfo.orderNumber }}</span>
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="goToOrders">查看订单</el-button>
          <el-button type="warning" @click="continueShopping">继续购物</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { CircleCheck } from '@element-plus/icons-vue'

const selectedMethod = ref('')
const showSuccessDialog = ref(false)

// 支付方式
const paymentMethods = ref([
  {
    id: 'alipay',
    name: '支付宝',
    icon: '/api/placeholder/40/40'
  },
  {
    id: 'wechat',
    name: '微信支付',
    icon: '/api/placeholder/40/40'
  },
  {
    id: 'unionpay',
    name: '银联支付',
    icon: '/api/placeholder/40/40'
  },
  {
    id: 'bank',
    name: '网银支付',
    icon: '/api/placeholder/40/40'
  }
])

// 订单信息
const orderInfo = ref({
  orderNumber: 'ORD' + Date.now(),
  totalPrice: 899,
  shippingFee: 0,
  discount: 0
})

// 计算最终金额
const finalAmount = computed(() => {
  return orderInfo.value.totalPrice + orderInfo.value.shippingFee - orderInfo.value.discount
})

// 方法
const selectMethod = (methodId) => {
  selectedMethod.value = methodId
}

const confirmPayment = () => {
  if (!selectedMethod.value) {
    ElMessage.warning('请选择支付方式')
    return
  }

  // 模拟支付过程
  const loading = ElLoading.service({
    lock: true,
    text: '正在支付中...',
    background: 'rgba(0, 0, 0, 0.7)'
  })

  setTimeout(() => {
    loading.close()
    showSuccessDialog.value = true
  }, 2000)
}

const cancelPayment = () => {
  ElMessageBox.confirm('确定要取消支付吗？', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  }).then(() => {
    console.log('取消支付')
  })
}

const goToOrders = () => {
  showSuccessDialog.value = false
  console.log('跳转到订单页面')
}

const continueShopping = () => {
  showSuccessDialog.value = false
  console.log('继续购物')
}
</script>

<style scoped>
.payment-page {
  min-height: 100vh;
  background-color: #f5f5f5;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  background: linear-gradient(135deg, #ff8c00 0%, #ffa500 100%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.header-content {
  display: flex;
  align-items: center;
  padding: 15px 0;
  gap: 30px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.brand-name {
  font-size: 20px;
  font-weight: bold;
  color: white;
}

.page-title h2 {
  color: white;
  margin: 0;
  font-size: 18px;
  font-weight: 500;
}

/* Main Content */
.main-content {
  padding: 30px 0;
}

.payment-wrapper {
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin: 0 0 20px 0;
  padding: 20px 30px 0 30px;
}

/* Payment Methods */
.payment-methods {
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 20px;
}

.method-list {
  padding: 0 30px;
}

.method-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.3s;
}

.method-item:last-child {
  margin-bottom: 0;
}

.method-item.active {
  border-color: #ff8c00;
  background-color: #fff4e6;
}

.method-item:hover {
  border-color: #ff8c00;
}

.method-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.method-icon {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  background-color: #f0f0f0;
}

.method-name {
  font-size: 16px;
  font-weight: 500;
  color: #333;
}

/* Order Summary */
.order-summary {
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 20px;
}

.order-info {
  padding: 0 30px;
}

.order-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 16px;
}

.order-item.total {
  border-top: 1px solid #f0f0f0;
  margin-top: 10px;
  padding-top: 15px;
  font-weight: 600;
}

.item-label {
  color: #666;
}

.item-value {
  color: #333;
}

.item-value.discount {
  color: #27ae60;
}

.item-value.final-amount {
  font-size: 20px;
  font-weight: bold;
  color: #e74c3c;
}

/* Security Tips */
.security-tips {
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 20px;
}

.tips-list {
  padding: 0 30px;
  margin: 0;
  list-style: none;
}

.tips-list li {
  color: #666;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 8px;
  position: relative;
  padding-left: 15px;
}

.tips-list li::before {
  content: '•';
  color: #ff8c00;
  position: absolute;
  left: 0;
}

/* Payment Actions */
.payment-actions {
  padding: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.amount-display {
  display: flex;
  align-items: center;
  gap: 10px;
}

.amount-label {
  font-size: 16px;
  color: #666;
}

.amount-value {
  font-size: 24px;
  font-weight: bold;
  color: #e74c3c;
}

.action-buttons {
  display: flex;
  gap: 15px;
}

.pay-btn {
  padding: 12px 30px;
  font-size: 16px;
  font-weight: 600;
}

/* Success Dialog */
.success-content {
  text-align: center;
  padding: 20px;
}

.success-icon {
  font-size: 64px;
  margin-bottom: 20px;
}

.success-content h3 {
  color: #333;
  margin: 0 0 15px 0;
  font-size: 20px;
}

.success-content p {
  color: #666;
  margin: 0 0 20px 0;
  line-height: 1.6;
}

.order-number {
  background: #f8f9fa;
  padding: 10px;
  border-radius: 4px;
  color: #666;
  font-size: 14px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 15px;
    text-align: center;
  }

  .payment-actions {
    flex-direction: column;
    gap: 20px;
    text-align: center;
  }

  .action-buttons {
    width: 100%;
    flex-direction: column;
  }

  .pay-btn {
    width: 100%;
  }
}
</style>